
/**  
* Project Name:e3-item-web  
* File Name:ItemController.java  
* Package Name:cn.e3mall.item.controller  
* Date:2019年5月23日上午10:47:02  
* Copyright (c) 2019, chenzhou1025@126.com All Rights Reserved.  
*  
*/

package com.huixi.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.huixi.common.pojo.TbItem;
import com.huixi.entity.Item;
import com.huixi.entity.ItemDesc;
import com.huixi.entity.User;
import com.huixi.service.ItemService;
import com.huixi.service.LoginService;
import com.huixi.utils.JsonResult;

/**
 * ClassName:ItemController <br/>
 * Function: 商品展示Controller <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2019年5月23日 上午10:47:02 <br/>
 * 
 * @author 韦丽娜
 * @version
 * @since JDK 1.6
 * @see
 */
@Controller
public class ItemController {

	@Autowired
	private ItemService itemService;
	
	@Autowired
	private LoginService loginService;

	@RequestMapping("/item/{itemId}")
	public String showItemInfo(@PathVariable long itemId, Model model, HttpServletRequest request,
			HttpSession session) {
		// 调用服务取商品基本信息
		Item item = itemService.getItemById(itemId);
		TbItem tbItem = new TbItem(item);
		// 取商品描述
		ItemDesc itemDesc = itemService.getItemDescById(itemId);

		// 把信息传递给页面
		model.addAttribute("item", tbItem);
		model.addAttribute("itemDesc", itemDesc);
		
		JsonResult jsonResult = loginService.getUserBySession(session);
		request.setAttribute("userInfo", (User) jsonResult.getData());
		// 返回逻辑视图
		return "item";
	}

}
